#encoding:utf-8
import os , sys 

try:
	from py_ex import *
except:
	import logging
from PIL import Image


def resizeBatch(texture , sizelist , tarlist):
	img = Image.open(texture)
	index = 0
	tmpimg = {}
	for size in sizelist:
		tmpimg[index] = img.resize(size ,Image.ANTIALIAS)

		path_base = os.path.split(tarlist[index])[0]
		if not os.path.isdir(path_base):
			os.mkdir(path_base)

		tmpimg[index].save(tarlist[index])
		logging.info("Resize the Imgge [%s] to [%s] (%s)" % (texture , tarlist[index] , size))
		index = index + 1

def resizeSingle(texture, sizew , sizeh , tardir):
	img = Image.open(texture)
	img.resize((sizew , sizeh) , Image.ANTIALIAS)

	path_base = os.path.splie(texture)[0]
	filename_base = os.path.splie(texture)[1]

	try:
		tarfile = os.path.join(tardir , filename_base)
		if os.path.isfile(tarfile):
			os.remove(tarfile)
		ret.save(tarfile)
		logging.info("Resize the Imgge [%s] to [%s]" % (texture , tardir))
	except:
		logging.error("@!Save texture failed")